from Models.Market_Model import m
from Models import tp_SQL
from datetime import date,timedelta,datetime

class DataApi():
    @classmethod
    def getDailyIncome(cls,lag=-30): 
        endDate,startDate=str(date.today()),str(date.today()+timedelta(days=lag))
        label='dailyIncome:'+'-'.join([startDate,endDate])        
        res=m.DataQueryMongo(sql=tp_SQL.sql_daily_income_interval.format(startDate,endDate),key=label)
        return res
        
    @classmethod
    def getMonthlyIncome(cls,dt=date.today().strftime("%Y")):  
        label='MonthlyIncome:'+'-'.join([dt])        
        res=m.DataQueryMongo(sql=tp_SQL.sql_monthly_income.format(dt),key=label)
        return res
    
    @classmethod
    def getGoodsTotalIncome(cls):        
        res=m.DataQueryMongo(sql=tp_SQL.sql_goods_total_income,key='GoodsTotalIncome')
        return res
    
    @classmethod 
    def getGoodsTotalIncomeByOrder(cls):        
        res=m.DataQueryMongo(sql=tp_SQL.sql_goods_total_income_order,key='GoodsTotalIncomeByOrder')
        return res
 
    @classmethod
    def getGoodsDailyIncome(cls,dt='2020-01-01'):  
        label = 'GoodsDailyIncome-' + dt     
        res=m.DataQueryMongo(sql=tp_SQL.sql_daily_goods_income.format(dt),key=label)
        return res
        
    @classmethod
    def getDailyHourlyIncome(cls,dt='2020-01-01'): 
        label = 'GoodsDailyHourlyIncome-' + dt    
        res=m.DataQueryMongo(sql=tp_SQL.sql_daily_hourly_income.format(dt),key=label)
        return res    
    
    @classmethod
    def getUserDailyExpense(cls,dt='2020-01-01'): 
        label = 'UserDailyExpense50-' + dt     
        res=m.DataQueryRedis(sql=tp_SQL.sql_vip_daily_expense.format(dt),key=label,item=label)
        return res       
        
    @classmethod
    def getSomeUserDailyExpense(cls,userID='vip10',startDate='2020-01-01',endDate='2020-05-01'): 
        label = 'sql_daily_expense_vip-'+userID + '-'.join([startDate,endDate])   
        res=m.DataQueryRedis(sql=tp_SQL.sql_daily_expense_vip.format(userID,startDate,endDate),key=label,item=label)
        return res         
        
    @classmethod
    def getUserTotalExpense(cls): 
        label = 'UserTotalExpense50'      
        res=m.DataQueryRedis(sql=tp_SQL.sql_vip_total_expense,key=label,item=label)
        return res    
    
    @classmethod     
    def getUserFavoriteGoods(cls,userID): 
        label = 'UserFavoriteGoods-1'+userID      
        res=m.DataQueryRedis(sql=tp_SQL.sql_vip_favorate_items.format(userID),key=label,item=label)
        return res        

